package com.sanyang.lawyer.controller.hr;

import com.sanyang.lawyer.ResultApi.ResponseResult;
import com.sanyang.lawyer.entity.*;
import com.sanyang.lawyer.service.hr.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import javax.servlet.http.HttpServletRequest;
import java.util.*;

@RestController
@RequestMapping("HrEmp")
public class HrController {

    @Autowired
    private HrEmpService hrEmpService;

    @Autowired
    private HrPositionService hrPositionService;

    @Autowired
    private HrIdentService hrIdentService;

    @Autowired
    private HrEducationService hrEducationService;

    @Autowired
    private HrNationService hrNationService;
    @Autowired
    private HrdegreeService hrdegreeService;
    @Autowired
    private HrWorkhistoryService hrWorkhistoryService;
    @Autowired
    private HrTeamService hrTeamService;

    @RequestMapping("listALl")
    public Map<String,Object>listAll(Hr_emp emp, HttpServletRequest request){
        HrFlexigrid hrFlexigrid = new HrFlexigrid(emp,request);
        Map<String,Object>map=new HashMap<String,Object>();
        List<Hr_emp> list=hrEmpService.listALLPage(hrFlexigrid);
        Integer count=hrEmpService.listALLCount(emp);
        map.put("code",0);
        map.put("msg","");
        map.put("count",count);
        map.put("data",list);
        return map;
    }
    //添加
    @RequestMapping("add")
    public String insert(Hr_emp hr_emp){
        int i=hrEmpService.save(hr_emp);
        if(i==1){
            return "1";
        }else{
            return "0";
        }
    }

    //修改
    @RequestMapping("update")
    public String update(Hr_emp hr_emp){
        int i= hrEmpService.update(hr_emp);
        if(i==1){
            return "1";
        }else{
            return "0";
        }

    }
    @RequestMapping("getByid")
    public Hr_emp getByid(int empId){
        Hr_emp hrEmp=hrEmpService.getById(empId);
        return hrEmp;
    }
    //删除
    @RequestMapping("del")
    public String del(String empId,String empState){
        int i=hrEmpService.delete(empId,empState);
        if(i==1){
            return "1";
        }else{
            return "0";
        }
    }
    //身份
    @RequestMapping("position")
    public List<HrPosition> listAll(HrPosition hrPosition){
        List<HrPosition> list=hrPositionService.listAll(hrPosition);
        return list;
    }
    //证件类型
    @RequestMapping("ident")
    public List<HrIdent>identlistAll(HrIdent hrIdent){
        List<HrIdent> list=hrIdentService.listAll(hrIdent);
        return list;
    }
    //学历
    @RequestMapping("education")
    public List<HrEducation> educationlistAll(HrEducation hrEducation){
        List<HrEducation> list=hrEducationService.listAll(hrEducation);
        return list;
    }

    //名字
    @RequestMapping("nation")
    public List<HrNation> educationlistAll(HrNation hrNation){
        List<HrNation> list=hrNationService.listAll(hrNation);
        return list;
    }
    //工作经历
    @RequestMapping("workgetByid/{id}")
    public Map<String,Object> workgetByid(@PathVariable("id") Integer  id){
        Map<String,Object> map=new HashMap<>();
        List<HrWorkhistory> list2=hrWorkhistoryService.getByid(id);
        Integer i=list2.size();
        map.put("code",0);
        map.put("count",i);
        map.put("msg","");
        map.put("data",list2);
        return map;
    }
    //教育经历
    @RequestMapping("degreegetByid/{id}")
    public Map<String,Object> degreegetByid(@PathVariable("id") Integer id){
        Map<String,Object> map=new HashMap<>();
        List<HrDegree> list2=hrdegreeService.getByid(id);
        Integer i=list2.size();
        map.put("code",0);
        map.put("count",i);
        map.put("msg","");
        map.put("data",list2);
        return map;
    }
    //添加工作经历
    @RequestMapping("workinsert")
    public String workinsert(HrWorkhistory hrWorkhistory){
        int i =hrWorkhistoryService.save(hrWorkhistory);
        if(i==1){
            return "1";
        }else{
            return "0";
        }
    }
    //添加教育经历
    @RequestMapping("degreeinsert")
    public String degreeinsert(HrDegree hrDegree){
        int i=hrdegreeService.save(hrDegree);
        if(i==1){
            return "1";
        }else{
            return "0";
        }
    }
    //workID
    @RequestMapping("workid")
    public HrWorkhistory workid(int id){
        HrWorkhistory hrWorkhistory=hrWorkhistoryService.workid(id);
        return hrWorkhistory;
    }
    //degreeid
    @RequestMapping("degreeid")
    public HrDegree degreeid(int id){
        HrDegree hrDegree=hrdegreeService.degreeid(id);
        return hrDegree;
    }
    //修改work
    @RequestMapping("workupdate")
    public String workupdate(HrWorkhistory hrWorkhistory){
        int i=hrWorkhistoryService.update(hrWorkhistory);
         if(i==1){
             return "1";
         }else{
             return "0";
         }
    }
    //修改degree
    @RequestMapping("degreeupdate")
    public String degreeupdate(HrDegree hrDegree){
        int i=hrdegreeService.update(hrDegree);
        if(i==1){
            return "1";
        }else{
            return "0";
        }
    }
    @RequestMapping("workdel")
    public String workdel(String id){
        int i=hrWorkhistoryService.delete(id);
        if(i==1){
            return "1";
        }else{
            return "0";
        }
    }
    @RequestMapping("degreedel")
    public String degreedel(String id){
        int i=hrdegreeService.delete(id);
        if(i==1){
            return "1";
        }else{
            return "0";
        }
    }
    @RequestMapping("team")
    public Map<String,Object> teamlistAll(HrTeam hrTeam, HttpServletRequest request){
        HrFlexigrid hrFlexigrid = new HrFlexigrid(hrTeam, request);
        Map<String,Object>map=new HashMap<String,Object>();
        List<HrTeam> list=hrTeamService.listALLPage(hrFlexigrid);
        Integer count=hrTeamService.listALLCount(hrTeam);
        map.put("code",0);
        map.put("msg","");
        map.put("count",count);
        map.put("data",list);
        return map;
    }
    @RequestMapping("teaminsert")
    public String teaminsert(HrTeam hrTeam){
        int i =hrTeamService.insert(hrTeam);
        if(i==1){
            return "1";
        }else{
            return "0";
        }
    }
    @RequestMapping("teamupdate")
    public String teamupdate(HrTeam hrTeam){
        int i=hrTeamService.update(hrTeam);
        if(i==1){
            return "1";
        }else{
            return "0";
        }
    }
    @RequestMapping("teamdel")
    public String teamdel(String id){
        int i=hrTeamService.delete(id);
        if(i==1){
            return "1";
        }else{
            return "0";
        }
    }

    @RequestMapping("selectList")
    public ResponseResult<List<Hr_emp>> selectList() {
        return ResponseResult.success(hrEmpService.selectList());
    }
    
}
